import requests
import time
import math
import random
import base64
import json
import requests
def get_code():
    t = str(int(time.time()*100))
    a = str(random.random())[0:6]
    dataStr = t + a
    url = 'http://membernew.yundasys.com:15116/ydaccount/getImageCode?dataStr={}'.format(dataStr)
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
    }
    res = requests.get(url,headers=headers)
    with open('yd.png','wb') as f:
        f.write(res.content)
        f.close()
    return dataStr

def base64_api(uname, pwd, img, typeid):
    with open(img, 'rb') as f:
        base64_data = base64.b64encode(f.read())
        b64 = base64_data.decode()
    data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}
    result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)
    if result['success']:
        return result["data"]["result"]
    else:
        return result["message"]

def get_login(code,datastr):
    print(type(code),type(datastr))
    t = str(int(time.time()*1000))
    url = 'http://membernew.yundasys.com:15116/opserver/ydmb/interface.do?action=member.account_new.login_new_check_code&version=V1.0&req_time={}&appid=ydmb&data=%7B%22loginName%22%3A%2218998474263%22%2C%22password%22%3A%2255dc4d3819c1fa586ab163a95de28ed8%22%2C%22validCode%22%3A%22{}%22%2C%22sessionid%22%3A%22{}%22%7D'.format(t,code,datastr)
    headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest'
    }
    # int(time.time()*1000)
    # data = "{action: member.account_new.send_message_with_image_code,version: V1.0,appid: ydmb,req_time: {},data: {'type':'bindMem','mobile':'18998474263','password':'55dc4d3819c1fa586ab163a95de28ed8','validcode':{},'sessionid':{}}}".format(str(int(time.time()*1000)),code,datastr)
    res = requests.get(url,headers=headers)
    print(res.json())
    print(res.headers)


def get_data():
    url = 'http://membernew.yundasys.com:15116/opserver/ydmb/interface.do?action=member.order.orderList&req_time=1626075917063&version=V1.0&appid=ydmb&openid=eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJtZW1iZXIueXVuZGFleC5jb20iLCJpYXQiOjE2MjYwNzU3MjgsImF1ZCI6InlkbWIiLCJzdWIiOiJlYjNkMWViMzg5MDU0ZjliODBjNGUyOWUwOTA5YmY1NyIsImV4cCI6MTYyNjA4MjkyOH0.5DeN2jO3MjGyyZe7svpqOGahybpQhzveMVPhv6U3AOIkIy-VdzOc6FflSZ69ln-vSprrtfMCKH-dSYtF4ztWLA&data=%7B%22type%22%3A%22R%22%2C%22currentPage%22%3A%221%22%2C%22pageSize%22%3A%2210%22%2C%22condition%22%3A%22%22%2C%22orderStatus%22%3A%22%22%2C%22startDate%22%3A%222021-06-12%22%2C%22endDate%22%3A%222021-07-12%22%7D'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67',
        'Cookie': 'ydgw=j1572nuao6eu3oeb1v2nkapn8b; mykey=eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJtZW1iZXIueXVuZGFleC5jb20iLCJpYXQiOjE2MjcwMTAwNzcsImF1ZCI6InlkbWIiLCJzdWIiOiIyOTQ2MTMxNzA4ODU0ODg2NCIsImV4cCI6MTYyNzAxNzI3N30.NIe0xmnlncv7nus9uxYyFPs2NOq7MFO2ZcFxzBXpI5klI2xePAcqlGnKz8vhKutE2Byuj7Bl3CJw6cAvULZaHw'
    }
    res = requests.get(url,headers=headers)
    print(res.json())


if __name__ == "__main__":
    # datastr = get_code()
    # img_path = "E:\\node项目\\yd.png"
    # result = input("请输入验证码")
    # get_login(result,datastr)
    get_data()
    